﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PhoneBilling.Models;

namespace PhoneBilling.Controllers
{
    public static class StaticData
    {
        private static List<Data> areaTypeList;
        public static List<Data> AreaTypeList
        {
            get 
            {
                if(areaTypeList == null)
                    LoadAreaTypeList();

                return areaTypeList;
            }
        }

        public static void LoadAreaTypeList()
        {
            SanDiDbsEntities entities = new SanDiDbsEntities();
            var list = (from a in entities.OBJDefine
                        where a.ObjectID == "AREATYPE"
                        orderby a.ItemID
                        select a);
            areaTypeList = new List<Data>();
            foreach (var item in list)
            { 
                Data data = new Data();
                data.Name = item.ItemID.Trim();
                data.FullName = string.Format("{0}.{1}",item.ItemID.Trim(),item.ItemName.Trim());
                areaTypeList.Add(data);
            }
        }

        private static List<Data> sliceList;
        public static List<Data> SliceList
        {
            get
            {
                if (sliceList == null)
                    LoadSliceList();

                return sliceList;
            }
        }

        public static void LoadSliceList()
        {
            SanDiDbsEntities entities = new SanDiDbsEntities();
            var list = (from a in entities.OBJDefine
                        where a.ObjectID == "SLICE"
                        orderby a.ItemID
                        select a);
            sliceList = new List<Data>();
            foreach (var item in list)
            {
                Data data = new Data();
                data.Name = item.ItemID.Trim();
                data.FullName = string.Format("{0}.{1}", item.ItemID.Trim(), item.ItemName.Trim());
                sliceList.Add(data);
            }
        }

        private static List<Data> feeTypeList;
        public static List<Data> FeeTypeList
        {
            get
            {
                if (feeTypeList == null)
                    LoadFeeTypeList();

                return feeTypeList;
            }
        }

        public static void LoadFeeTypeList()
        {
            feeTypeList = new List<Data>()
            {
                new Data(){Name = "B",FullName = "B.基本费"},
                new Data(){Name = "E",FullName = "E.附加费"},
                new Data(){Name = "S",FullName = "S.服务费"},
            };
        }

        private static List<Data> gradeList;
        public static List<Data> GradeList
        {
            get
            {
                if (gradeList == null)
                    LoadGradeList();

                return gradeList;
            }
        }

        public static void LoadGradeList()
        {
            SanDiDbsEntities entities = new SanDiDbsEntities();
            var list = (from a in entities.OBJDefine
                        where a.ObjectID == "GRADE"
                        orderby a.ItemID
                        select a);
            gradeList = new List<Data>();
            foreach (var item in list)
            {
                Data data = new Data();
                data.Name = item.ItemID.Trim();
                data.FullName = string.Format("{0}.{1}", item.ItemID.Trim(), item.ItemName.Trim());
                gradeList.Add(data);
            }
        }

        private static List<Data> tariffList;
        public static List<Data> TariffList
        {
            get
            {
                if (tariffList == null)
                    LoadTariffList();

                return tariffList;
            }
        }

        public static void LoadTariffList()
        {
            SanDiDbsEntities entities = new SanDiDbsEntities();
            var list = (from a in entities.OBJDefine
                        where a.ObjectID == "TARIFFID"
                        orderby a.ItemID
                        select a);
            tariffList = new List<Data>();
            foreach (var item in list)
            {
                Data data = new Data();
                data.Name = item.ItemID.Trim();
                data.FullName = string.Format("{0}.{1}", item.ItemID.Trim(), item.ItemName.Trim());
                tariffList.Add(data);
            }
        }
    }

    public class Data
    {
        public string Name{get;set;}
        public string FullName{get;set;}
    }
}